package org.phytodata.actionengine;

import java.io.InputStream;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.pentaho.platform.api.engine.IFileInfo;
import org.pentaho.platform.api.engine.ISolutionFile;
import org.pentaho.platform.api.engine.SolutionFileMetaAdapter;
import org.pentaho.platform.engine.core.solution.FileInfo;

public class GroovyFileMetaProvider extends SolutionFileMetaAdapter {

  private Log logger = LogFactory.getLog(GroovyFileMetaProvider.class);

  public GroovyFileMetaProvider() {
  }

  @Override
  public IFileInfo getFileInfo(ISolutionFile solutionFile, InputStream in) {
    try {
      IFileInfo info = new FileInfo();
      info.setAuthor("Dr Suess");
      info.setDescription("Some Description");
      info.setDisplayType("Some DisplayType");
      info.setTitle(solutionFile.getFileName());
      return info;
    } catch (Exception e) {
      logger.error("Error creating meta information for file type " + solutionFile.getExtension(), e); //$NON-NLS-1$
      return null;
    }

    //    Document doc = null;
    //    try {
    //      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    //      DocumentBuilder builder = factory.newDocumentBuilder();
    //      doc = builder.parse(in);
    //      
    //      String result = "dashboard";  //$NON-NLS-1$
    //      
    //      XPath xpath = XPathFactory.newInstance().newXPath();
    //      String author = (String) xpath.evaluate("/cdf/author", doc, XPathConstants.STRING); //$NON-NLS-1$
    //      String description = (String) xpath.evaluate("/cdf/description", doc, XPathConstants.STRING); //$NON-NLS-1$
    //      String icon = (String) xpath.evaluate("/cdf/icon", doc, XPathConstants.STRING); //$NON-NLS-1$
    //      String title = (String) xpath.evaluate("/cdf/title", doc, XPathConstants.STRING); //$NON-NLS-1$
    //
    //      IFileInfo info = new FileInfo();
    //      info.setAuthor(author);
    //      info.setDescription(description);
    //      info.setDisplayType(result);
    //      info.setIcon(icon);
    //      info.setTitle(title);
    //      return info;
    //
    //    } catch (Exception e) {
    //      logger.error("Error parsing grv file", e); //$NON-NLS-1$
    //      return null;
    //    }
  }
}
